#include <iostream>
#include <iomanip>

using std::cout;

#include "Complex.h"


ostream &operator<<( ostream &output, const Complex &c )
{
    if( c.imaginary < 0 )
        output << "[" << c.real << c.imaginary << "i]";
    else
        output << "[" << c.real << "+" << c.imaginary << "i]";

    return output;
}

istream &operator>>( istream &input, Complex &c )
{
    input >> c.real;
    input.ignore(); // Pula "\n"
    input >> c.imaginary;

    return input;
}

Complex::Complex( double realPart, double imaginaryPart ) :
    real(realPart), imaginary(imaginaryPart)
{
}

Complex Complex::operator+( const Complex &operand2 ) const
{
    return Complex( real + operand2.real, imaginary + operand2.imaginary);
}

Complex Complex::operator-( const Complex &operand2 ) const
{
    return Complex( real - operand2.real, imaginary - operand2.imaginary );
}

Complex Complex::operator*( const Complex &c ) const
{
    double realPart;
    double imaginaryPart;

    realPart = real * c.real - imaginary * c.imaginary;
    imaginaryPart = real * c.imaginary + imaginary * c.real;

    return Complex( realPart, imaginaryPart );
}

bool Complex::operator==( const Complex &c ) const
{
    if( (real == c.real ) && (imaginary == c.imaginary) )
        return true;
    
    return false;
}

bool Complex::operator!=( const Complex &c ) const
{
    if( (real != c.real ) || (imaginary != c.imaginary) )
        return true;
    
    return false;
}


